<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['setting']=$this->plugin_setting('basic');
//print_r($basic['hdps']);exit;
if($_RQ['op']=='main'){
	/*******main*******/
	//明星员工
	$managers=pdo_getall('jy_smallquan_manager',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'),'','','score desc limit 0,5');
	$sql = "SELECT SUM(money) FROM " . tablename('jy_smallquan_plan') . " WHERE uniacid=:uniacid";
    $money = pdo_fetch($sql,array(":uniacid" => $_SESSION['uniacid']));
	$count = $money['SUM(money)'];
	
	//公告
	$notices=pdo_getall('jy_smallquan_notice',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'),'','','createtime desc limit 0,5');
	//设备类型
	$devices=pdo_getall('jy_smallquan_device_classify','');
	$return['managers']=$managers;
	$return['devices']=$devices;
	$return['notices']=$notices;
	$return['count']=$count;
	set_html('title',$return['setting']['quan_title']?'首页-'.$return['setting']['quan_title']:'首页-小周圈社区');
	$return['sharedata']=array(
		'title'=>$return['setting']['share_title'],
		'desc'=>$return['setting']['share_desc'],
		'link'=>custom_url('jy_smallquan/index/',true),
		'imgUrl'=>ATTACHMENT_URL.$return['setting']['share_image'],
	);
	$fuwu=pdo_getall('jy_smallquan_apart_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'));
	$star5=pdo_count('jy_smallquan_apart_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','star'=>'5'));
	$star4=pdo_count('jy_smallquan_apart_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','star'=>'4'));
	$star3=pdo_count('jy_smallquan_apart_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','star'=>'3'));
	$star2=pdo_count('jy_smallquan_apart_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','star'=>'2'));
	$star1=pdo_count('jy_smallquan_apart_assess',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','star'=>'1'));
	$fuwu_count=count($fuwu);
	if($fuwu_count>0){
		$fuwu['star5']=$star5/$fuwu_count*100;
		$fuwu['star4']=$star4/$fuwu_count*100;
		$fuwu['star3']=$star3/$fuwu_count*100;
		$fuwu['star2']=$star2/$fuwu_count*100;
		$fuwu['star1']=$star1/$fuwu_count*100;
	}else{
		$fuwu['star5']=$fuwu['star4']=$fuwu['star3']=$fuwu['star2']=$fuwu['star1']=0;
	}
	//获取用户当月评价
	$month_assess=pdo_get('jy_smallquan_apart_assess',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'time'=>date('Y-m')));
	//评价平均分
	$sql = "SELECT SUM(star) FROM " . tablename('jy_smallquan_apart_assess') . " WHERE uniacid=:uniacid";
	$sum = pdo_fetch($sql,array(":uniacid" => $_SESSION['uniacid']));	
	$star_sum = $sum['SUM(star)'];
	$star_fen=number_format($star_sum/$fuwu_count,1)?number_format($star_sum/$fuwu_count,1):4.6;
	//查询我的管家
	$hid=pdo_getcolumn('jy_smallquan_household',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'hid');
	$bid=pdo_getcolumn('jy_smallquan_house',array('uniacid'=>$_SESSION['uniacid'],'id'=>$hid),'bid');
	$guanjia=pdo_get('jy_smallquan_manager',array('uniacid'=>$_SESSION['uniacid'],'bid'=>$bid,'status'=>'1'));
	$pingjianum=pdo_count('jy_smallquan_manager_assess',array('uniacid'=>$_SESSION['uniacid'],'managerid'=>$guanjia['id']));
	$pinjia_good=pdo_count('jy_smallquan_manager_assess',array('uniacid'=>$_SESSION['uniacid'],'managerid'=>$guanjia['id'],'isgood'=>'1'));
	$guanjia['manyidu']=number_format($pinjia_good/$pingjianum,0);
	$guanjia['pingjianum']=$pingjianum;
	$return['fuwu']=$fuwu;
	$return['guanjia']=$guanjia;
	$return['post']=array('star'=>$month_assess['star']);
	$return['month']=date('m');
	$return['month_assess']=$month_assess;
	$return['star_fen']=$star_fen;
	$return['fuwu_count']=$fuwu_count;
	exi($return);
}